package com.crud.couverters;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;

import com.crud.bean.Department;
import com.crud.bean.Employee;

@Controller
public class EmployeeCouverter implements Converter<String, Employee> {

	@Override
	public Employee convert(String source) {
		Employee employee = new Employee();
		if (!StringUtils.isEmpty(source.trim())) {
			//GG-gg@csii.com-0-105
			String[] emp = source.split("-");
			if (emp != null && emp.length == 4) {
				employee.setLastName(emp[0]);
				employee.setEmail(emp[1]);
				employee.setGerder(Integer.parseInt(emp[2]));
				Department department = new Department();
				department.setId(Integer.parseInt(emp[3]));
				employee.setDepartment(department);;
			}
		}
		System.out.println(source + employee);
		return employee;
	}

	
	
}
